import request from '../../../components/Request';

export async function listMenuTree() {
  let result = await request.post({ url: './module/listMenuTree.do' });
  return result.data;
}


export async function listApp() {
  let result = await request.post({ url: './module/listApp.do' });
  return result.data;
}


export async function saveModule(module) {
  // 过滤掉资源路径为空的配置项
  let moduleResList = [];
  module.resList.map(function(item) {
    if (item.value != null && item.value != '') {
      moduleResList.push(item);
    }
  });
  module.resList = moduleResList;

  let result = await request.post({
    url: './module/saveModule.do',
    data: module,
    contentType: request.CONTENT_TYPE_JSON,
  });
  return result.data;
}

export async function deleteModule(id) {
  let result = await request.post({ url: './module/deleteModule.do', data: { id: id } });
  return result.data;
}

export async function sort(data) {
  let result = await request.post({ url: './module/sort.do', data: data });
  return result.data;
}

export async function listModuleRes(moduleId) {
  let result = await request.post({ url: './module/listModuleRes.do', data: { moduleId: moduleId } });
  if (result.data && result.data.length > 0) {
    return result.data;
  } else {
    return [{}];
  }
}
